function [res] = gmm_multi3ik(ERROR_SERIES,INSTRUMENTS,P)

global WEIGHT_WT_1 WEIGHT_WT_2;

% Checking the validity of instruments
res.dd = det(INSTRUMENTS'*INSTRUMENTS/size(INSTRUMENTS,1));
% % true process
% U = randn(110,2);
% ERROR_SERIES = U(3:102,:);      % size is 100 x 2
% INSTRUMENTS = [ones(100,1), U(2:101,:), U(1:100,:)];    % size is 100 x 5
% estimation
par0 = [0.5; 0.5; 0.5]; % starting values are the true values
[parGMM_2, fGMM_2, retcodeGMM_2,parGMM_1, fGMM_1, retcodeGMM_1] = GMMmultiloss3(par0);
res.alfa_1 = parGMM_1(end,:);
J1 = size(ERROR_SERIES,1)*fGMM_1;
res.Jtest_1 = J1;
res.alfa_2 = parGMM_2(end,:);
J2 = size(ERROR_SERIES,1)*fGMM_2;
res.Jtest_2 =J2;
nn = size(INSTRUMENTS,2);
cval90 = chi2inv(0.90,3 * nn - 3);
cval95 = chi2inv(0.95,3 * nn - 3);
cval99 = chi2inv(0.99,3 * nn - 3);
res.test_res90_1 = (res.Jtest_1(end,1)<=cval90);
res.test_res95_1 = (res.Jtest_1(end,1)<=cval95);
res.test_res99_1 = (res.Jtest_1(end,1)<=cval99);
res.test_res90_2 = (res.Jtest_2(end,1)<=cval90);
res.test_res95_2 = (res.Jtest_2(end,1)<=cval95);
res.test_res99_2 = (res.Jtest_2(end,1)<=cval99);
PAR_GMM_1 = res.alfa_1';
PAR_GMM_2 = res.alfa_2';
% % testing the symmetry of alphas
% TT = size(ERROR_SERIES,1);
% dd = size(PAR_GMM_2,1);
% stderrm2 = []; res_sym2_1m = []; res_sym2_2m = []; res_sym2_3m = []; res_sym2_4m = [];
% stderrm1 = []; res_sym1_1m = []; res_sym1_2m = []; res_sym1_3m = []; res_sym1_4m = [];
% %delta = (0.4:0.01:0.5)'; % smoothing parameter
% delta = 0.5;
% for inddel = 1:1:size(delta,1)
%     Gama2 = PPgrad('ObjFctGMMmulti2G',dd, PAR_GMM_2, TT, delta(inddel)); 
%     Gama1 = PPgrad('ObjFctGMMuni1G',dd, PAR_GMM_1, TT, delta(inddel)); 
%     % computing the var-covar matrix of the estimator at the optimum
%     CovMatrix2 = inv(Gama2*WEIGHT_WT_2*Gama2')/TT;  stderr2 = diag(CovMatrix2,0).^0.5;
%     CovMatrix1 = inv(Gama1*WEIGHT_WT_1*Gama1')/TT;  stderr1 = diag(CovMatrix1,0).^0.5;    
%     % symmetry Wald-type tests
%     % alpha1 = alpha2 = 0.5 alpha3 unrestricted
%     R1 = zeros(2,3); R1(1,1) = 1; R1(2,2) = 1;      % combination on coefficients matrix
%     sym2_1 = (PAR_GMM_2(1:2)-[0.5;0.5])'*inv(R1*CovMatrix2*R1')*(PAR_GMM_2(1:2)-[0.5;0.5]);
%     sym1_1 = (PAR_GMM_1(1:2)-[0.5;0.5])'*inv(R1*CovMatrix1*R1')*(PAR_GMM_1(1:2)-[0.5;0.5]);
%     res_sym2_1 = (sym2_1 <= chi2inv(.90,size(R1,1)));
%     res_sym1_1 = (sym1_1 <= chi2inv(.90,size(R1,1)));
%     stderrm2 = [stderrm2; stderr2']; % stores standard errors of alphas for all deltas
%     stderrm1 = [stderrm1; stderr1']; 
%     res_sym2_1m = [res_sym2_1m; res_sym2_1]; 
%     res_sym1_1m = [res_sym1_1m; res_sym1_1]; 
%     % alpha1 = 0.5 other alphas unrestricted 
%     sym2_2 = (PAR_GMM_2(1) - 0.5)^2/stderr2(1)^2; sym1_2 = (PAR_GMM_1(1) - 0.5)^2/stderr1(1)^2; 
%     res_sym2_2 = (sym2_2 <= chi2inv(.90,1)); res_sym1_2 = (sym1_2 <= chi2inv(.90,1));
%     res_sym2_2m = [res_sym2_2m; res_sym2_2]; res_sym1_2m = [res_sym1_2m; res_sym1_2];
%     % alpha2 = 0.5 other unrestricted
%     sym2_3 = (PAR_GMM_2(2) - 0.5)^2/stderr2(2)^3; sym1_3 = (PAR_GMM_1(2) - 0.5)^2/stderr1(2)^2; 
%     res_sym2_3 = (sym2_3 <= chi2inv(.90,1)); res_sym1_3 = (sym1_3 <= chi2inv(.90,1));
%     res_sym2_3m = [res_sym2_3m; res_sym2_3]; res_sym1_3m = [res_sym1_3m; res_sym1_3];
%     % alpha3 = 0.5 other unrestricted
%     sym2_4 = (PAR_GMM_2(3) - 0.5)^2/stderr2(3)^2; sym1_4 = (PAR_GMM_1(3) - 0.5)^2/stderr1(3)^2; 
%     res_sym2_4 = (sym2_4 <= chi2inv(.90,1)); res_sym1_4 = (sym1_4 <= chi2inv(.90,1));
%     res_sym2_4m = [res_sym2_4m; res_sym2_4]; res_sym1_4m = [res_sym1_4m; res_sym1_4];    
% end
% res2.stderrm2 = stderrm2;
% res2.stderrm1 = stderrm1;
% res2.res_sym2_1m = res_sym2_1m;
% res2.res_sym1_1m = res_sym1_1m;
% res2.res_sym2_2m = res_sym2_2m;
% res2.res_sym1_2m = res_sym1_2m;
% res2.res_sym2_3m = res_sym2_3m;
% res2.res_sym1_3m = res_sym1_3m;
% res2.res_sym2_4m = res_sym2_4m;
% res2.res_sym1_4m = res_sym1_4m;









